package com.gyx.lottery.dao.mapper;

import com.gyx.lottery.dao.dataobject.Encrypt;
import com.gyx.lottery.dao.dataobject.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user  (email,identity,password,phone_number,user_name)"
    +" values (#{email},#{identity},#{password},#{phoneNumber},#{userName})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(UserDO userDO);
@Select("select count(*) from user where phone_number= #{phoneNumber}")
    int countByPhone(@Param("phoneNumber") Encrypt phoneNumber);
    @Select("select count(*) from user where email= #{email}")
    int countByMail(@Param("email") String email);
@Select("select * from user where email = #{email}")
    UserDO selectByMail(@Param("email")String email);
    @Select("select * from user where phone_number= #{phoneNumber}")
    UserDO selectByPhone(Encrypt phoneNumber);

@Select("  <script> " +
        "select * from user " +
        "<if test=\"identity!=null\">" +
        " where identity=#{identity}</if> order by id desc" +
        " </script>")
    List<UserDO> selectUserByIdentity(@Param("identity") String identity);
    @Select("<script>"+
            " select id from user where id in " +
            " <foreach item='item' collection='items' open='(' separator=',' close=')' > " +
            "  #{item}  " +
            "  </foreach> "+
            " </script>"
    )
    List<Long> findIdByIds(@Param("items")List<Long> userIds);
    @Select("<script>" +
            " select * from user where id in" +
            " <foreach collection='items' item='item' open='(' separator=',' close=')' > " +
            " #{item}"  +
            " </foreach>"+
            " </script>")
    List<UserDO> batchSelectByIds(@Param("items") List<Long> userIds);
}
